<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>送货单打印</title>
		<script src='${ctxPath}/assets/mui/js/jquery-1.11.3.js'></script>
	</head>
	<style>
		p{
			font-size: 9px;
			height: 2px;
		}
		.button{
			background-color: #A6A6A6; color: black; /* Green */
		    border: none;
		    color: white;
		    padding: 10px 32px;
		    text-align: center;
		    text-decoration: none;
		    display: inline-block;
		    font-size: 14px;
    	}
	</style>
	<body>
		<div style="width: 100;">
			<button id="button" class="button" onclick="doPrint()">打印</button>
		</div>
		<div id="big" style="width: 100%;">
		</div>
		<script type="text/jscript">
			//通过URL 获取参数
			function GetQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if(r != null) return unescape(r[2]);
				return null;
			};
			var dispatchNumber = GetQueryString("dispatchNumber");
			var getUnitid = GetQueryString("getUnitid");
			var getLocationid = GetQueryString("getLocationid");
			load();
			function load(){
				var big = $("#big");
				$.ajax({
				    url:'${ctxPath}/tDispatch/printlist',
				    type:'post',
				    dataType:'json',
				    data:{"dispatchNumber":dispatchNumber,"getUnitid":getUnitid,"getLocationid":getLocationid},
				    success:function(data){
						var list= data.data
						if(list.length > 0){
							var songhuo = '<div id="-title" style="width: 100%; height: 20px;text-align: center;">'+
													'<h5 style="height: 2px;">送货单</h5>'+
												'</div>'+
												'<div id="-title-l" style="width: 100%; height: 20px;">'+
													'<h6 style="float: left; width: 50%;height: 2px;">收货单位：'+list[0].getUnit+'</h6>'+
													'<h6 style="float: right;width: 50%; text-align: right;height: 2px;">收货地点：'+list[0].getLocation+''+
												'</div>'+
												'<div id="-title-l" style="width: 100%; height: 20px;">'+
													'<h6 style="float: left; width: 50%;height: 2px;">联系人：'+list[0].getPeople+'</h6>'+
													'<h6 style="float: right;width: 50%; text-align: right;height: 2px;">联系电话：'+list[0].getTel+''+
												'</div>';

								songhuo += '<div id="order-title" style="width: 100%;height: 60px;margin-top: 40px;">'+
												'<div id="order-title-1" style="width: 100%;">'+
													'<p style="float: left; width: 26%;">运输单号：'+list[0].dispatchNumber+'</p>'+
													'<p style="float: left; width: 24%;">车牌号：'+list[0].carnumbger+'</p>'+
													'<p style="float: left; width: 24%;">司机：'+list[0].driver1+'</p>'+
													'<p style="float: right; width: 24%;">司机电话：'+list[0].cartel+'</p>'+
												'</div>'+
											'</div>';

							var ncont = 0.0;
							var vcont = 0.0;
							songhuo += '<div id="order-date" style="width: 100%;height: auto;">'+
													'<table id="order-table" style="width: 100%; font-size: 9px;" border="1px solid" cellpadding="0" cellspacing="0">'+
														'<thead>'+
															'<th>客户单号</th>'+
															'<th>商品名称</th>'+
															'<th>体积</th>'+
															'<th>数量</th>'+
														'</thead>'+
														'<tbody>';
							$.each(list,function(key,value){
								ncont += value.tooDeployNum*1;
								vcont += value.tooDeployVolume*1;
								songhuo += '<tr>'+
														'<td>'+value.customerOrder+'</td>'+
														'<td>'+value.goodsName+'</td>'+
														'<td>'+value.tooDeployVolume+'</td>'+
														'<td>'+value.tooDeployNum+'</td>'+
													'</tr>';
							});
							songhuo += '<tr>'+
													'<td>合计：</td>'+
													'<td></td>'+
													'<td>'+Math.round(ncont * 100) / 100+'</td>'+
													'<td>'+Math.round(vcont * 100) / 100+'</td>'+
												'</tr>';
												songhuo += '</tbody>'+
										'</table>'+
									'</div>';			
												
												
												
							big.append(songhuo);
						}
				    },
				    error: function(data){
						alert("查询送货明细异常!");
				    }
				});
			};
			//打印
			function doPrint() {
		        bdhtml = window.document.body.innerHTML;
		        phtnl = window.document.getElementById("big").innerHTML;
		        window.document.body.innerHTML = phtnl; //把需要打印的指定内容赋给big
		        window.print(); //调用浏览器的打印功能打印指定区域
		        window.document.body.innerHTML=bdhtml; // 最后还原页面
		    };
		    //打印的回调
		    var beforePrint = function() {
		        //打印前调用
		    };
		    var afterPrint = function() {
		        //打印后调用
		    };
		    if (window.matchMedia) {
		        var mediaQueryList = window.matchMedia('print');
		        mediaQueryList.addListener(function(mql) {
		            if (mql.matches) {
		                beforePrint();
		            } else {
		                afterPrint();
		            }
		        });
		    }
		</script>
	</body>
</html>